var DeptPersonSelect = function () {
  var template = /*html*/ `
    <div class="dept-person-select">
      <el-button class="form-btninput" plain @click="showSelect">
        <div class="select-content">
          <div class="select-input">
            {{getShowStr()}}
          </div>
          <div class="select-icon">
            <i class="el-icon-arrow-up" :class="{'is-reverse':isShow}"></i>
          </div>
        </div>
      </el-button>

      <el-dialog append-to-body title="请选择部门人员" :visible.sync="isShow" top="10vh" width="50%">
        <div style="height:calc(80vh - 54px);overflow:auto">
          <div class="dept-person-select-dialog-content">
            <dept-transfer ref="peopleSelect" v-if="isShow" v-model="deptPerson" :persons="options" mode="attendance">
            </dept-transfer>
          </div>
          <div class="dept-person-select-dialog-btns">
            <el-button type="primary" size="small" @click="ensure">确定</el-button>
            <el-button type="danger" size="small" @click="isShow=false">取消</el-button>
          </div>
        </div>
      </el-dialog>
    </div>
  `;

  return {
    props: {
      value: {
        type: Object,
        required: true
      },

      options: {
        type: Array,
        default: []
      }
    },

    computed: {
      deptPerson: function () {
        var obj = _.cloneDeep(this.value);
        obj.depts = _.map(obj.depts, 'id');
        obj.persons = _.map(obj.persons, 'id');
        return obj;
      }
    },

    data: function () {
      return {
        isShow: false
      };
    },

    methods: {
      showSelect: function () {
        this.isShow = true;
      },

      ensure: function () {
        this.isShow = false;
        var data = this.$refs['peopleSelect'].getData();
        this.$emit('input', data);
      },

      getShowStr: function () {
        var obj = this.value;
        var depts = _.map(obj.depts, 'name');
        var persons = _.map(obj.persons, 'name');
        var strArr = [];
        strArr.pushArray(depts);
        strArr.pushArray(persons);
        if (strArr.length > 2){
          strArr = strArr.slice(0,2);
          return `${strArr.join(',')}等`;
        }
        return strArr.join(',')
      }
    },

    components: {
      DeptTransfer: DeptTransfer
    },

    template: template
  };
}();